admin: Assume we're using /ostree if there's a toplevel /usr
authorColin Walters <walters@verbum.org>
Mon, 18 Mar 2013 22:11:00 +0000 (18:11 -0400)
committerColin Walters <walters@verbum.org>
Mon, 18 Mar 2013 22:11:00 +0000 (18:11 -0400)
Mainly so admin install works without an existing /ostree again.

src/ostree/ot-admin-builtin-install.c
src/ostree/ot-admin-functions.c

index 06249a952a2d97ee44e2183b899ccad677442085..5f5fb3d103ba6a48f23a709ce16ef17f34aadeaa 100644 (file)
@@ -96,6 +96,13 @@ ot_admin_builtin_install (int argc, char **argv, OtAdminBuiltinOpts *admin_opts,
       goto out;
     }
 
+  if (admin_opts->ostree_dir == NULL)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "No existing /ostree found; use --ostree-dir");
+      goto out;
+    }
+
   if (!ot_admin_ensure_initialized (admin_opts->ostree_dir, cancellable, error))
     goto out;
 
index f28ea73c56f9844b5d53dc60e130fb2ac53c3c32..c0b71a5fcd074c39b494cf9422761a1e6f7b18df 100644 (file)
@@ -440,6 +440,9 @@ ot_admin_get_default_ostree_dir (GFile        **out_ostree_dir,
   gboolean ret = FALSE;
   gs_unref_object GFile *possible_ostree_dir = NULL;
   gs_unref_object GFile *ret_ostree_dir = NULL;
+  gs_unref_object GFile *host_usr = NULL;
+
+  host_usr = g_file_new_for_path ("/usr");
 
   if (ret_ostree_dir == NULL)
     {
@@ -452,7 +455,11 @@ ot_admin_get_default_ostree_dir (GFile        **out_ostree_dir,
     {
       g_clear_object (&possible_ostree_dir);
       possible_ostree_dir = g_file_new_for_path ("/ostree");
-      if (g_file_query_exists (possible_ostree_dir, NULL))
+      /* If there's also /usr, we assume we're outside an ostree root
+       * and thus should use /ostree.
+       */
+      if (g_file_query_exists (possible_ostree_dir, NULL) ||
+          g_file_query_exists (host_usr, NULL))
         ret_ostree_dir = g_object_ref (possible_ostree_dir);
     }